package com.study.design.pattern.pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: gongsl
 * @Date: 2025-03-16 15:06
 * @description: 文件夹类
 */
public class Directory extends FileSystemNode {

    private List<FileSystemNode> subNodes = new ArrayList<>();

    public Directory(String name) {
        super(name);
    }

    @Override
    public boolean isFile() {
        return false;
    }

    @Override
    public int countNumOfFiles() {
        int numOfFiles = 0;
        for (FileSystemNode fileOrDir : subNodes) {
            numOfFiles += fileOrDir.countNumOfFiles();
        }
        return numOfFiles;
    }

    public void addSubNode(FileSystemNode fileOrDir){
        subNodes.add(fileOrDir);
    }
}
